#!/bin/bash

cargo fmt --all
cargo clippy --workspace --tests --benches

status=$?
if [ $status -ne 0 ]; then
    echo
    echo "--> cargo clippy check failed"
    echo
    exit $status
fi

declare -a crates=(
    "kaspa-wasm"
)

for crate in "${crates[@]}"
do
    cargo clippy -p $crate --target wasm32-unknown-unknown --tests --benches --features wasm32-sdk
    status=$?
    if [ $status -ne 0 ]; then
        echo
        echo "--> wasm32 check of $crate failed"
        echo
        exit $status
    fi
done

declare -a crates=(
    "kaspa-wrpc-wasm"
    "kaspa-wallet-cli-wasm"
    "kaspa-wasm"
    "kaspa-cli"
    "kaspa-daemon"
)

for crate in "${crates[@]}"
do
    cargo clippy -p $crate --target wasm32-unknown-unknown --tests --benches
    status=$?
    if [ $status -ne 0 ]; then
        echo
        echo "--> wasm32 check of $crate failed"
        echo
        exit $status
    fi
done

declare -a features=(
    "wasm32-rpc"
    "wasm32-core"
    "wasm32-sdk"
)

for feature in "${features[@]}"
do
    cargo clippy -p kaspa-wasm --target wasm32-unknown-unknown --features $feature
    status=$?
    if [ $status -ne 0 ]; then
        echo
        echo "--> wasm32 check of kaspa-wasm --features $feature has failed"
        echo
        exit $status
    fi
done
